package com.ruoyi.web.controller.doctor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doctor.domain.DoctorPatientHistory;
import com.ruoyi.doctor.service.DoctorPatientHistoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史病例Controller
 *
 * @author ruoyi
 * @date 2022-11-13
 */
@RestController
@RequestMapping("/doctor/history")
public class DoctorPatientHistoryController extends BaseController
{
    @Autowired
    private DoctorPatientHistoryService doctorPatientHistoryService;
    /**
     * 根据患者主键分页查询历史病历
     * @param doctorPatientHistory
     * @return
     */
    @GetMapping("/listByPatientId")
    public TableDataInfo listByPatientId(DoctorPatientHistory doctorPatientHistory){

        startPage();//开启分页
        return getDataTable(doctorPatientHistoryService.selectListByPatientId(doctorPatientHistory));
    }
    /**
     * 新增历史病例
     * @param doctorPatientHistory
     * @return
     */
    //@PreAuthorize("@ss.hasPermi('system:history:add')")
    //@Log(title = "历史病例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorPatientHistory doctorPatientHistory)
    {
        //设置新增数据的用户
        doctorPatientHistory.setCreateBy(SecurityUtils.getUsername());
        int rows = doctorPatientHistoryService.insertDoctorPatientHistory(doctorPatientHistory);
        if (rows ==0){
            //新增病例失败
            return AjaxResult.error();
        }
        return AjaxResult.success(doctorPatientHistory);
    }

    /**
     * 修改历史病例
     */
    @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "历史病例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorPatientHistory doctorPatientHistory)
    {
        return toAjax(doctorPatientHistoryService.updateDoctorPatientHistory(doctorPatientHistory));
    }

    /**
     * 删除历史病例
     */
    @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "历史病例", businessType = BusinessType.DELETE)
    @DeleteMapping("/{historyIds}")
    public AjaxResult remove(@PathVariable Long[] historyIds)
    {
        return toAjax(doctorPatientHistoryService.deleteDoctorPatientHistoryByHistoryIds(historyIds));

    }
}

